<?php

/*

  Action	$4

  Trash a card from your hand. Gain a card costing up to $2 more than the trashed card.

 */

class Remodel extends Card implements iAction, iKingdom, iBasic {

    public function __construct() {
        parent::__construct("Remodel", 4);
        $this->undoPlay = false;
        $this->undoBuy = true;
    }

    public function getDescription() {
        return array(
            "Trash a card from your hand. Gain a card costing up to $2 more than the trashed card.");
    }

    public function play(Game $game, $isRealCard) {

        $playhand = $game->getPlayHand();
        if (sizeof($playhand) > 0) {

            $playhand = getUniqueCards($playhand);
            if (sizeof($playhand) > 1) {
                $output = MySocket::GetUserReply($game, Input_ChooseOne, $playhand, 1, 1, null, "Choose a card to trash");
                $old_card_name = $output[0];
            } else {
                $old_card_name = $playhand[0];
            }

            $old_card = $game->moveCardFromPileToPile($old_card_name, PlayHand, Trash);
            ScreenDisplay::addScreenMessage($game, true, "trash " . nicePrint($old_card), "trashes " . ScreenDisplay::$LMSG);

            $price = $old_card->getPrice($game);
            $new_price = $price->add(2);
            $optional_cards = $game->getBoardCardsByPrice(new Price(), $new_price);
            if (sizeof($optional_cards) > 0) {
                $output = MySocket::GetUserReply($game, Input_ChooseOne, $optional_cards, 1, 1, null, "Choose a card to gain");

                $new_card_name = $output[0];
                $new_card = $game->moveCardFromPileToPile($new_card_name, BoardCards, DiscardPile);
                ScreenDisplay::addScreenMessage($game, false, " and gain " . nicePrint($new_card), " and gains " . ScreenDisplay::$LMSG);
            }
        } else {
            ScreenDisplay::addScreenMessage($game, true, "trash nothing", "trashes nothing");
        }

        $game->cardActionFinished();
        return true;
    }

}

?>